package com.iot.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iot.fire.domain.DWaterMessage;
import com.iot.fire.mapper.DWaterMessageMapper;
import com.iot.fire.service.IDWaterMessageService;
import org.springframework.stereotype.Service;

/**
 * @PackageName: com.iot.fire.service.impl
 * @ClassName: DWaterMessageServiceImpl
 * @Description:
 * @Author: czl
 * @Date: 2025/11/10 23:17
 */
@Service
public class
DWaterMessageServiceImpl extends ServiceImpl<DWaterMessageMapper, DWaterMessage> implements IDWaterMessageService {

    /**
     * 根据设备sn获取最新的消息
     * @param deviceSn
     * @return
     */
    @Override
    public DWaterMessage getLastWaterMessageByDeviceSn(String deviceSn) {
        LambdaQueryWrapper<DWaterMessage> wrapper = Wrappers.lambdaQuery(DWaterMessage.class);
        wrapper.eq(DWaterMessage::getSN, deviceSn).orderByDesc(DWaterMessage::getTime);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }
}
